package com.lmc.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lmc.R;
import com.lmc.entity.RecreationDetails;

import java.util.List;

public class RecreationListAdapter extends BaseAdapter {
    Context context;
    List<RecreationDetails.DataBean.ItemsBean> list;

    public RecreationListAdapter(Context context, List<RecreationDetails.DataBean.ItemsBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public RecreationDetails.DataBean.ItemsBean getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.recreation_info_list_item, null);
            holder = new ViewHolder();
            holder.play_layout = convertView.findViewById(R.id.play_layout);
            holder.no_play_layout = convertView.findViewById(R.id.no_play_layout);
            holder.name_1 = convertView.findViewById(R.id.name_1);
            holder.name_2 = convertView.findViewById(R.id.name_2);
            holder.position = convertView.findViewById(R.id.position);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        RecreationDetails.DataBean.ItemsBean item = getItem(position);
        if (item.getTag() == 0) {
            holder.play_layout.setVisibility(View.GONE);
            holder.no_play_layout.setVisibility(View.VISIBLE);
        } else {
            holder.play_layout.setVisibility(View.VISIBLE);
            holder.no_play_layout.setVisibility(View.GONE);
        }
        holder.name_1.setText(item.getName());
        holder.name_2.setText(item.getName());


        holder.position.setText(String.valueOf(position + 1));

        return convertView;
    }

    private class ViewHolder {
        LinearLayout play_layout, no_play_layout;
        TextView name_1, name_2, position;
    }
}
